package iscript.gameFramework.IsoLibarys.data 
{
	import iscript.coreFramework.math.Point2D;
	
	public class IsoBound
	{
		/**
		 * 
		 * @param	grid0  Row Column
		 * @param	grid1  Row Column
		 * @param	isoscene
		 */
		public function IsoBound(grid0:Point2D,grid1:Point2D=null)
		{
		    if (grid1 == null){grid1 = grid0.clone();}
			_topGrid = new Point2D(Math.min(grid0.x, grid1.x), Math.min(grid0.y, grid1.y));
			_bottomGrid = new Point2D(Math.max(grid0.x, grid1.x), Math.max(grid0.y, grid1.y));
		}
			
		public  function clone():IsoBound {
			   return new IsoBound(_topGrid,_bottomGrid);
			}
		
		public  function get row():int {
			  if (IsEmtry()) return 0;
			  return  int(_bottomGrid.x - _topGrid.x) + 1;
			};
		
		public  function get column():int { 
			 if (IsEmtry()) return 0;
			  return  int(_bottomGrid.y - _topGrid.y) + 1;
			};
		
		public  function get leftGrid():Point2D { 
			 if (IsEmtry()) new Point2D(-1,-1);
			   return new Point2D(_bottomGrid.x, _topGrid.y);
			};
		
		public  function get rightGrid():Point2D { 
			if (IsEmtry()) new Point2D(-1,-1);
			   return new Point2D(_topGrid.x, _bottomGrid.y);
			};
		
		private var  _topGrid:Point2D;
		public  function set topGrid(value:Point2D):void {_topGrid = value;};
		public  function get topGrid():Point2D { return  _topGrid;};
		 
		private var  _bottomGrid:Point2D;
		public  function set bottomGrid(value:Point2D):void { _bottomGrid = value;};
		public  function get bottomGrid():Point2D { return _bottomGrid;};
			
		public  function  IsEmtry():Boolean {
			  return  _topGrid == null || _bottomGrid == null;
			}	
			
		public function toString():String {
			  return  "topGrid:" + topGrid+"::"+"bottomGrid"+bottomGrid;		
			}
		 
		public function isInside(bound:IsoBound):Boolean {			
			 return  this.topGrid.x >= bound.topGrid.x && this.topGrid.y >= bound.topGrid.y &&  this.bottomGrid.x <= bound.bottomGrid.x && this.bottomGrid.y<=this.bottomGrid.y;
			}	
		
		public function isOutside(bound:IsoBound):Boolean {
			 return  !isInside(bound) ;
			}	
			
			
		static public function  create(topX:int,topY:int,bottomX:int,bottomY:int):IsoBound {
			return new IsoBound(new Point2D(topX, topY), new Point2D(bottomX, bottomY));
			}
			
		static public function 	createByColumnRow(topX:int, topY:int, column:int, row:int):IsoBound {
			  var bottomPoint2D:Point2D = new Point2D( topX + column - 1, topY + row - 1);
			  return new IsoBound(new Point2D(topX, topY), bottomPoint2D);
			}
			
	}

}

 